#include "widget.h"
#include "ui_widget.h"
#include <QShortcut>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->horizontalSlider->setMinimum(100);
    ui->horizontalSlider->setMaximum(2000);
    ui->horizontalSlider->setValue(800);
    ui->horizontalSlider->setSingleStep(50);

    ui->verticalSlider->setMinimum(100);
    ui->verticalSlider->setMaximum(1500);
    ui->verticalSlider->setValue(600);
    ui->verticalSlider->setSingleStep(50);

    QShortcut* shortCut_w = new QShortcut(this);
    shortCut_w->setKey(QKeySequence("w"));
    QShortcut* shortCut_s = new QShortcut(this);
    shortCut_s->setKey(QKeySequence("s"));
    QShortcut* shortCut_a = new QShortcut(this);
    shortCut_a->setKey(QKeySequence("a"));
    QShortcut* shortCut_d = new QShortcut(this);
    shortCut_d->setKey(QKeySequence("d"));

    connect(shortCut_w, &QShortcut::activated, this, &Widget::hander_w);
    connect(shortCut_s, &QShortcut::activated, this, &Widget::hander_s);
    connect(shortCut_a, &QShortcut::activated, this, &Widget::hander_a);
    connect(shortCut_d, &QShortcut::activated, this, &Widget::hander_d);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_horizontalSlider_valueChanged(int value)
{
    const QRect& rect = this->geometry();
    this->setGeometry(rect.x(), rect.y(), value, rect.height());
}

void Widget::on_verticalSlider_valueChanged(int value)
{
    const QRect& rect = this->geometry();
    this->setGeometry(rect.x(), rect.y(), rect.width(), value);
}

void Widget::hander_w()
{
    int value = ui->verticalSlider->value();
    if(value >= ui->verticalSlider->maximum())
    {
       return;
    }
    ui->verticalSlider->setValue(value + ui->verticalSlider->singleStep());
}

void Widget::hander_s()
{
    int value = ui->verticalSlider->value();
    if(value <= ui->verticalSlider->minimum())
    {
       return;
    }
    ui->verticalSlider->setValue(value - ui->verticalSlider->singleStep());
}

void Widget::hander_a()
{
    int value = ui->horizontalSlider->value();
    if(value <= ui->horizontalSlider->minimum())
    {
       return;
    }
    ui->horizontalSlider->setValue(value - ui->horizontalSlider->singleStep());
}

void Widget::hander_d()
{
    int value = ui->horizontalSlider->value();
    if(value >= ui->horizontalSlider->maximum())
    {
       return;
    }
    ui->horizontalSlider->setValue(value + ui->horizontalSlider->singleStep());
}
